const errorMap = require('../constant/error-map')

class ApplicationError extends Error {
  constructor(message) {
    super(message)
    this.name = 'ApplicationError'
  }
}

class ParameterError {
  constructor(message = errorMap.PARAM_ERROR.message) {
    this.name = '参数错误'
    this.code = errorMap.PARAM_ERROR.code
    this.message = message
  }
}

class AuthError {
  constructor(type) {
    this.name = type
    this.code = type.code
    this.message = type.message
  }
}

class BusinessLogicError {
  constructor(type) {
    this.name = type
    this.code = errorMap[type].code
    this.message = errorMap[type].message
  }
}

// 权限不足的报错
class PermissionDeniedError {
  constructor() {
    this.name = '权限不足'
    this.code = errorMap.PERMISSION_DENIED_ERROR.code
    this.message = errorMap.PERMISSION_DENIED_ERROR.message
  }
}

module.exports = {
  ParameterError,
  AuthError,
  ApplicationError,
  BusinessLogicError,
  PermissionDeniedError
}
